﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace BGShell.Components
{
    public sealed class DataTipItemCollection : Collection<DataTipItem>
    {
        internal DataTipItemCollection()
        {
        }

        public void AddRange(IEnumerable<DataTipItem> items)
        {
            foreach (var item in items)
            {
                Add(item);
            }
        }

        protected override void ClearItems()
        {
            foreach (var item in Items)
            {
                item.Index = -1;
            }

            base.ClearItems();
        }

        protected override void InsertItem(int index, DataTipItem item)
        {
            item.Index = index;
            base.InsertItem(index, item);
        }

        protected override void RemoveItem(int index)
        {
            Items[index].Index = -1;
            base.RemoveItem(index);
        }

        protected override void SetItem(int index, DataTipItem item)
        {
            if (index < Count)
            {
                Items[index].Index = -1;
            }

            item.Index = index;
            base.SetItem(index, item);
        }
    }
}
